#ifndef POINT_H
#define POINT_H

#include <assert.h>
#include <set>
#include <vector>
#include <stdlib.h>

#define PI 3.14159265

class Point
{
public:
	//CTR
	Point()
	{}

	Point(double x, double y, double theta) : d(3), indx(-1)
	{
		//coordinates.reserve(d);
		coordinates.push_back(x);
		coordinates.push_back(y);
		coordinates.push_back(theta);
	}

	//accesors
	double at(int i)  const		//returns the i'th coordinate of the point
	{
		return coordinates[i];
	}
	double operator[](int i) const //returns the i'th coordinate of the point
	{
		assert (i >= 0 && i <d);
		return at(i);
	}

	bool operator==(const Point &other) const
	{
		if (dimension() != other.dimension())
			return false;

		for (int i =0; i < dimension(); i++)
		{
			if (at(i) != other[i])
				return false;
		}
		return true; 
	}

	bool operator!=(const Point &other) const
	{
		return !(*this == other);
	}

	int dimension() const
	{
		return d;
	}
	unsigned int index() const
	{
		return indx;
	}

	void set_index(unsigned int index) 
	{
		indx = index;
	}

	void set_angle(double ang)
	{
		coordinates[2] = ang;
	}

private:
	std::vector<double> coordinates;	//contain the Point coordinates

	//dimension
	int d;

	//index
	int indx;
}; //Point

struct Less_than_point_id
{
	bool operator()(const Point& p1, const Point& p2) const 
	{
		assert (p1.dimension() == p2.dimension());
		return ( p1.index() < p2.index());
	}
}; //Less_than_point_id

struct Less_than_point_lex
{
	bool operator()(const Point& p1, const Point& p2) const 
	{
		assert (p1.dimension() == p2.dimension());
		for (int i(0); i < p1.dimension(); ++i)
		{
			if (p1[i] != p2[i])
				return (p1[i] < p2[i]);
		}
		return false;
	}
}; //Less_than_point_lex

typedef std::set<Point, Less_than_point_id>		Point_set;

double squared_distance(const Point&p, const Point&q);
double distance_points(const Point&p, const Point&q);

double angle_of_line(const Point &a, const Point &b);
double smallest_angle(const Point &s, const Point &t);

#endif //POINT_H